<template>
  <div class="md:flex">
    <template v-for="(item, index) in growCardList" :key="item.title">
      <Card
        size="small"
        :loading="loading"
        :title="item.title"
        class="md:w-1/4 w-full !md:mt-0"
        :class="{ '!md:mr-4': index + 1 < 4, '!mt-4': index > 0 }"
      >
        <template #extra>
          <Tag :color="item.color">{{ item.action }}</Tag>
        </template>

        <div class="py-4 px-4 flex justify-between items-center">
          <CountTo :startVal="1" :endVal="item.value" class="text-4xl" />
          <Icon :icon="item.icon" :size="40" />
        </div>
      </Card>
    </template>
  </div>
</template>
<script lang="ts" setup>
  import { CountTo } from '/@/components/CountTo/index';
  import { Icon } from '/@/components/Icon';
  import { Tag, Card } from 'ant-design-vue';
  import { onMounted, ref } from 'vue';
  import { getStatus } from '/@/api/monitor/rule';

  defineProps({
    loading: {
      type: Boolean,
    },
  });

  interface GrowCardItem {
    icon: string;
    title: string;
    value: number;
    color: string;
    action: string;
  }

  async function getStatusData(lv: number) {
    const rsp: number = await getStatus({ length: 7 * 24, level: lv });
    growCardList.value[lv - 1].value = rsp;
  }

  const loadData = () => {
    getStatusData(1);
    getStatusData(2);
    getStatusData(3);
    getStatusData(4);
  };

  onMounted(() => {
    loadData();
  });

  const growCardList = ref<GrowCardItem[]>([
    {
      title: 'INFO级告警',
      icon: 'clarity:info-standard-line',
      value: 0,
      color: 'blue',
      action: '周',
    },
    {
      title: 'ERROR级告警',
      icon: 'clarity:error-standard-line',
      value: 0,
      color: 'orange',
      action: '周',
    },
    {
      title: 'FATAL级告警',
      icon: 'clarity:times-circle-line',
      value: 0,
      color: 'red',
      action: '周',
    },
    {
      title: '告警总数',
      icon: 'clarity:uninstall-line',
      value: 0,
      color: 'purple',
      action: '周',
    },
  ]);
</script>
